<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>axiosandvue联合使用</title>
</head>
<!-- 将请求到的数据通过vue渲染到页面上 -->

<body>
    <div id="app">
        <input type="button" value="点击获取笑话" @click="getjoke">
        <p> {{joke}} </p>
    </div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
    var app = new Vue({
        el: "#app",
        data: {
            joke: "好好笑这个笑话"
        },
        methods: {
            getjoke: function() {
                var that = this; //在axios中用this地址会出现改变，所以在外面先将他用一个变量保存起来
                axios.get("https://autumnfish.cn/api/joke").then(function(response) {
                    console.log(response.data); //respose是很多数据的集合，在这个集合中取出data
                    that.joke = response.data;
                })
            }
        }
    })
</script>

</html>